<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core">

<ui:composition template="/admin/common.xhtml">

	<ui:define name="content">
		<h:form>
			<div class="rows">
				<h1>News Management</h1>
			</div>
			<div class="rows">
				<div>
					<h:commandLink styleClass="btn btn-default" action="#{newsManagement.preAdd()}" value="Add news" />
				</div>
			</div>
			<div class="rows">
				<c:if test="${newsManagement.resultMes != null}">
					<div class="alert  alert-info alert-dismissible" role="alert" style="margin-top: 8px">
						<button type="button" class="close" data-dismiss="alert">
							<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
						</button>
						${newsManagement.resultMes}
					</div>
			</c:if>
			</div>
			<div class="rows" style="margin-top: 10px">
				<table class="table table-hover">
					<tr>
						<th class="text-center">Title</th>
						<th>Date</th>
						<th>User</th>
						<th>Category</th>	
						<th>Status</th>	
						<th>Action</th>	
					</tr>
					
					<c:forEach items="#{newsManagement.listNews}" var="news">
						<tr>
							<td class="col-md-3">
								<h:commandLink action="#{newsManagement.preEdit(news)}">
									<h5>#{news.title}</h5>
								</h:commandLink>
							</td>
							<td class="col-md-2">#{news.timeCreated}</td>
							<td class="col-md-2">#{news.user.userName}</td>
							<td class="col-md-2">#{news.category.categoryName}</td>
							<td class="col-md-1">#{news.active ? 'Enable':'Disable'}</td>
							<td class="col-md-1">
								<div class="btn-group">
									<h:commandLink styleClass="btn btn btn-default" action="#{newsManagement.preEdit(news)}">Edit</h:commandLink>
										<button type="button" class="btn btn btn-default dropdown-toggle"
											data-toggle="dropdown">
											<span class="caret"></span> <span class="sr-only">ToggleDropdown</span>
										</button>
										<ul class="dropdown-menu" role="menu">
											<li><h:commandLink
													action="#{newsManagement.delete(news.newsId)}"
													value="Delete" /></li>
											<li><h:commandLink
													action="#{newsManagement.active(news)}"
													value="${news.active ? 'Disactive':'Active'}" /></li>
										</ul>
									</div>
							</td>
						</tr>
					</c:forEach>
				</table>
				
				
			
			
			</div>
		</h:form>
	</ui:define>

</ui:composition>
</html>